package com.neuronrobotics.opengl.scene;

import java.util.ArrayList;

public class GroupNode extends SceneNode{
	
	ArrayList<SceneNode> children;
	
	public GroupNode(){
		children = new ArrayList<SceneNode>();
	}
	
	public GroupNode(GroupNode parent){
		this();
		this.setParent(parent);
	}

	@Override
	protected boolean setParent(GroupNode newParent) {
		if(this.hasParent()&&parentNode.hasChild(this)) parentNode.removeChild(this);
		this.parentNode = newParent;
		if(!parentNode.hasChild(this)) this.parentNode.addChild(this);
		return true;
	}
	
	public boolean removeChild(SceneNode childNode) {
		return children.remove(childNode);		
	}

	public boolean hasChild(SceneNode child) {
		return children.contains(child);
	}

	public boolean addChild(SceneNode newChild){
		if(!children.contains(newChild)){
			return children.add(newChild);
		}
		return false;
	}
	
	public int getChildCount(){
		return children.size();
	}
	
	@Override
	protected void draw(float[] viewMatrix, float[] projMatrix) {
		if (this.isVisible) {
			for (SceneNode child : children) {
				child.draw(viewMatrix, projMatrix);
			}
		}
	}	
	
	

}
